<?php defined('SYSPATH') or die('No direct access allowed.');

/**
 * 微信小程序处理过滤函数
 * Class Model_Api_V2_Xcx
 */
class Model_Api_V2_Xcx
{

    public static function filter_content($content)
    {
        //删除视频链接的某些属性
        $content = St_Functions::del_video_attr($content);
        //给视频重置宽高
        $content = St_Functions::set_video_w_h($content);

        $pattern = "/<[img|IMG|video|VIDEO].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png|\.jpeg|\.mp4]))[\'|\"].*?[\/]?>/i";
        $content = preg_replace_callback(
            $pattern,
            function ($ma) {
                $newUrl = $ma[1];
                if (strpos($ma[1], 'http') === false) {
                    $newUrl = Model_Api_V2_System::uniapp_img($newUrl);
                }
                return str_replace($ma[1], $newUrl, $ma[0]);
            }, $content);

        return $content;  //;
    }

    public static function content_strip($content){
        $content = preg_replace('/<img[^>]*src\s*=\s*[\"|\']?\s*([^>\"\'\s]*)(\">|\"\/>)/i',"self::wap_img('$1')",$content);
        return $content;
    }

    public static function wap_img($url){
        $img='<img src="'.$url.'">';
        return $img;
    }

}